<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>Cadastro de Vendedores</title>
</h:head>
<ui:composition template="templatePrincipal.xhtml">
	<ui:define name="header">
		<ui:include src="header.xhtml" />
	</ui:define>

	<ui:define name="centro">
		<h:body>

			<p:growl id="messages" showDetail="true" life="1000" />
			<p:confirmDialog id="confirmRemoveDialog"
				message="Remover o vendedor ?" header="Remoção de vendedor"
				severity="alert" widgetVar="confirmation" appendToBody="true"
				update="messages">

				<p:commandButton id="confirm" value="Sim"
					oncomplete="confirmation.hide()"
					actionListener="#{vendedorController.removeVendedor}"
					update="messages,form1:tabview1:dataTable,form1:tabview1:dados" />

				<p:commandButton id="decline" value="Não"
					onclick="confirmation.hide()" type="button" />

			</p:confirmDialog>

			<h:form id="form1" prependId="false">

				<p:tabView id="tabview1" dynamic="true" cache="false">
					<p:ajax event="tabChange"
						listener="#{vendedorController.changeTabView}" update="novocli" />


					<p:tab id="tabpesq" title="Pesquisar">
						<p:panelGrid columns="1" style="width:100%">

							<f:facet name="header">
        						Vendedores
    							</f:facet>

							<p:panelGrid id="dados" columns="4" colspan="10"
								style="width:100%">

								<f:facet name="header">
        						Dados da pesquisa
    							</f:facet>

								<p:outputLabel for="pesqnome" value="Nome :" />
								<p:inputText id="pesqnome"
									value="#{vendedorController.pesqvendedor.nome}" size="80" />

								<p:outputLabel for="pesqcpf" value="CPF :" size="14" />
								<p:inputText id="pesqcpf"
									value="#{vendedorController.pesqvendedor.cpf}" />

								<p:outputLabel for="pesqtel" value="Telefone :" size="14" />
								<p:inputText id="pesqtel"
									value="#{vendedorController.pesqvendedor.tel}" />

								<p:outputLabel for="pesqemail1" value="Email 1:" />
								<p:inputText id="pesqemail1"
									value="#{vendedorController.pesqvendedor.email1}" size="40" />

								<p:outputLabel for="pesqemail2" value="Email 2 :" />
								<p:inputText id="pesqemail2"
									value="#{vendedorController.pesqvendedor.email2}" size="40" />

								<p:outputLabel for="pesqnomeconj" value="Nome do Conjuge :" />
								<p:inputText id="pesqnomeconj"
									value="#{vendedorController.pesqvendedor.nomeConjuge}"
									size="80" />

								<p:outputLabel for="pesqcpfconj" value="CPF do Conjuge:"
									size="14" />
								<p:inputText id="pesqcpfconj"
									value="#{vendedorController.pesqvendedor.cpfConjuge}" />

								<p:outputLabel for="pesqtelconj" value="Telefone :" size="14" />
								<p:inputText id="pesqtelconj"
									value="#{vendedorController.pesqvendedor.telConjuge}" />


								<p:commandButton value="Pesquisar"
									actionListener="#{vendedorController.pegarTodosVendedores}"
									update="dataTable,dados" />

							</p:panelGrid>

							<p:dataTable id="dataTable" var="vendedor"
								value="#{vendedorController.vendedorList}" paginator="true"
								rows="3"
								paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
								rowsPerPageTemplate="3,6,9"
								selection="#{vendedorController.resvendedor}"
								selectionMode="single" rowKey="#{vendedor.vendedor_id}">

								<p:ajax event="rowSelect"
									listener="#{vendedorController.rowSelect}"
									update=":form1:tabview1:dados" />


								<f:facet name="header">
            					Vendedores encontrados
        					</f:facet>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Nome" />
									</f:facet>
									<h:outputText value="#{vendedor.nome}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="CPF" />
									</f:facet>
									<h:outputText value="#{vendedor.cpf}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Telefone" />
									</f:facet>
									<h:outputText value="#{vendedor.tel}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Email 1" />
									</f:facet>
									<h:outputText value="#{vendedor.email1}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Email 2" />
									</f:facet>
									<h:outputText value="#{vendedor.email2}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Nome do conjuge" />
									</f:facet>
									<h:outputText value="#{vendedor.nomeConjuge}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="CPF do conjuge" />
									</f:facet>
									<h:outputText value="#{vendedor.cpfConjuge}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Tel. Conj." />
									</f:facet>
									<h:outputText value="#{vendedor.telConjuge}" />
								</p:column>

							</p:dataTable>

							<p:panelGrid id="botoes" columns="3" colspan="10">

								<p:commandButton value="Remover" onclick="confirmation.show()"
									type="button" />

								<p:commandButton value="Salvar"
									actionListener="#{vendedorController.saveVendedor}"
									update="dados,dataTable,:messages" />

								<p:commandButton value="Cancelar" type="reset" />

							</p:panelGrid>
						</p:panelGrid>

					</p:tab>

					<p:tab id="tabnovocli" title="Novo Vendedor">

						<p:panelGrid id="novocli" columns="4">
							<f:facet name="header">
        					Dados do Vendedor
    					</f:facet>

							<p:outputLabel for="novo_nome" value="Nome :" />
							<p:inputText id="novo_nome"
								value="#{vendedorController.vendedor.nome}" size="80" />

							<p:outputLabel for="novo_cpf" value="CPF :" size="14" />
							<p:inputText id="novo_cpf"
								value="#{vendedorController.vendedor.cpf}" />

							<p:outputLabel for="novo_tel" value="Telefone :" size="14" />
							<p:inputText id="novo_tel"
								value="#{vendedorController.vendedor.tel}" />

							<p:outputLabel for="novo_email1" value="Email 1:" />
							<p:inputText id="novo_email1"
								value="#{vendedorController.vendedor.email1}" size="40" />

							<p:outputLabel for="novo_email2" value="Email 2 :" />
							<p:inputText id="novo_email2"
								value="#{vendedorController.vendedor.email2}" size="40" />

							<p:outputLabel for="novo_nomeconj" value="Nome do Conjuge :" />
							<p:inputText id="novo_nomeconj"
								value="#{vendedorController.vendedor.nomeConjuge}" size="80" />

							<p:outputLabel for="novo_cpfconj" value="CPF do Conjuge:"
								size="14" />
							<p:inputText id="novo_cpfconj"
								value="#{vendedorController.vendedor.cpfConjuge}" />

							<p:outputLabel for="novo_telconj" value="Telefone :" size="14" />
							<p:inputText id="novo_telconj"
								value="#{vendedorController.vendedor.telConjuge}" />

							<p:commandButton value="Salvar"
								actionListener="#{vendedorController.createVendedor}"
								update="novocli,:messages" />

							<p:commandButton value="Cancelar" type="reset" />

						</p:panelGrid>

					</p:tab>

					<p:tab tab="importar" title="Importar">
						<p:panelGrid>
							<h:outputText value="Desenvolvimento futuro" />
						</p:panelGrid>
					</p:tab>
				</p:tabView>

			</h:form>
		</h:body>
	</ui:define>
</ui:composition>
</html>